package com.briup.ch11;

import java.io.*;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/16
 * @Description:
 */
public class Test10_ByteArray {
    public static void main(String[] args) throws IOException {
        //内存输出字节流ByteArrayOutputStream
        FileInputStream fileInputStream = new FileInputStream("test.txt");
        byte[] buffer = new byte[1024];
        int len = 0;
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        while((len=fileInputStream.read(buffer))!=-1){
            byteArrayOutputStream.write(buffer,0,len);
        }
        fileInputStream.close();
        System.out.println(byteArrayOutputStream.toString());
        //内存输入字节流ByteArrayInputStream
        byte[] bytes = {97,98,99,100,101,102};
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        FileOutputStream fileOutputStream = new FileOutputStream("test2.txt");
        int b = 0;
        while((b=byteArrayInputStream.read())!=-1){
            System.out.print((char)b);
            fileOutputStream.write(b);

        }
        byteArrayInputStream.close();
        byteArrayOutputStream.close();


    }
}
